﻿using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using MyTech.DataAccess.Common;

namespace MyTech.DataAccess.MsSQL
{
    public class DataAccessMsSQL : DataAccessSQLBase, IDatabase
    {
        public DataAccessMsSQL()
        {
            connectionString = ConfigurationManager.ConnectionStrings["MsSQL"].ConnectionString;

            if (null != connectionString)
            {
                _connection = new SqlConnection(connectionString);
            }
        }

        public int? ExecuteNonQuery(string sqlStmt)
        {
            int? response = null;
            //Create the command object
            var command = new SqlCommand(sqlStmt);
            response = ExecuteNonQuery(command);
            return response;
        }


        public DataSet ExecuteReader(string sqlStmt)
        {
            //Create the command object
            var command = new SqlCommand(sqlStmt);            
            var response = ExecuteReader(command);
            return response;
        }

        public DataSet ExecuteReader(string sqlStmt, SpParams spParams)
        {
            throw new System.NotImplementedException();
        }

        public object ExecuteScalar(string sqlStmt)
        {
            object response = null;
            //Create the command object
            var command = new SqlCommand(sqlStmt);            
            response = ExecuteScalar(command);
            return response;
        }

        public DbObjectType DbType
        {
            get
            {
                return DbObjectType.MsSQL;
            }
        }     
    }
}
